<template>
	<div class="table" v-if="rightDataSource.length>0">
		<top-search :num="nums" :time="time.toString()" @paramsChange="paramsChange" :searchText="searchText" />
		<a-spin :spinning="loading">
			<el-row style="margin-top: 10px;">
				<left-pane :itemClick="leftHandler" :dataSource="leftDataSource" />
				<right-pane :dataSource="rightDataSource" />
			</el-row>
		</a-spin>
		<Pagination @pagination="paramsChange" background :autoScroll="false" layout="total, prev, pager, next"
			:total="total" :limit="params.pageSize"/>
	</div>
  <a-empty style="padding-top: 100px;" description="暂无数据" v-else />
</template>

<script>
	import TopSearch from './components/TopSearch'
	import LeftPane from './components/LeftPane'
	import RightPane from './components/RightPane'
	import {
		book,
		book_f
	} from "@/api/public/index.js"
	export default {
		name: 'index',
		components: {
			TopSearch,
			LeftPane,
			RightPane
		},
		data() {
			return {
				loading: false,
				nums: 0,
				time: 0,
				params: {
					pageNum1: 1
				},
				total: 0,
				leftDataSource: [{
						title: '图书馆',
						data: [{
							label: '图书馆',
							value: 0
						}]
					},
					{
						title: '资源类型',
						data: [{
							label: '图书',
							value:0
						}]
					}
				],
				rightDataSource: [],
				subData: [],
			}
		},
		props: {
			searchText: {
				type: String,
				default: ''
			},
			list: {

			},
			num: {
				type: Number,
				default: 0
			},
			obj: {},

		},
		mounted() {

		},
		watch: {
			obj() {
				this.obj.pageSize1=this.params.pageSize1?this.params.pageSize1:this.obj.pageSize1
				if(this.obj.status==1){
					this.total=1
				}
				this.hq(this.obj)


			},
			//  list() {
			//    this.rightDataSource = this.list

			// },
			// num(){
			// 	this.nums=this.num
			// }
		},
		methods: {
			paramsChange(e) {
				this.params = {
					...this.params,
					...e
				}
				if (this._timeId) clearTimeout(this._timeId)
				this.loading = true
				this._timeId = setTimeout(() => {
					this.loading = false
				}, 1000)
				let value = {
					name: this.obj.name,
					type: this.obj.type,
					pageSize1: this.params.pageSize,
					pageNum1: this.params.page ? this.params.page : 1,
				}
				this.$emit('pageSize',this.params.pageSize)
				this.hq(value)


			},
			leftHandler(e) {

				//this.hq(this.params)
			},
			hq(value) {
				if (value.name == undefined || value.name == '') {
					this.$message({
						message: '输入搜索内容',
						type: 'warning'
					});
					return false
				}

				var sendDate = (new Date()).getTime();
				book_f(value).then(res => {
					if (res.code == 200) {
						this.rightDataSource = []
						this.rightDataSource.push(...res.rows)
						if (this.params.sort == 4) {
							this.rightDataSource.reverse()
						}
						this.nums = res.total
						this.leftDataSource.forEach((a)=>{
							a.data.forEach((b)=>{
								b.value=this.nums
							})

						})
						var x = res.total / 10; //测试的数字
						var y = String(x).indexOf(".") + 1; //获取小数点的位置
						var count = String(x).length - y; //获取小数点后的个数
						if (y > 0) {
							// alert("这个数字是小数，有" + count + "位小数");
							this.total = Math.ceil(res.total)
						} else {
							this.total = res.total
							//alert("不是小数");
						}
						var receiveDate = (new Date()).getTime();
						var responseTimeMs = receiveDate - sendDate;
						this.time=responseTimeMs/1000



					}
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.table {
		border: 1px solid #d8e2f0;
		padding: 23px 49px;
		background: #f7fafd;
		font-size: 14px;
		color: #333;
		padding-bottom: 120px;
	}
</style>
